﻿var phoneReg =/^1[345789][0-9]{9}$/;
var pwdReg =/^.{6,16}$/;
var isPhoneRight =false;
var isPwdRight =false;

phone.onkeyup= function(){
    var phoneValue = phone.value;
    if(!phoneReg.test(phoneValue)){
        phoneerror.innerHTML = "对不起，您的手机号码格式有误！";
        isPhoneRight = false;
    }else{
      phoneerror.innerHTML = "";
      isPhoneRight = true;
    }
    checkAll();
};
pwd.onkeyup = function(){
  var pwdValue = pwd.value;
  if(!pwdReg.test(pwdValue)){
    pwderror.innerHTML = "对不起，您的密码格式有误";
    isPwdRight = false;
  }else{
    pwderror.innerHTML = "";
    isPwdRight = true;
  }
  checkAll();
};
function checkAll(){
    if(isPhoneRight&&isPwdRight){
      loginBtn.className = "loginBtn loginBtn_active";
    }else{
      loginBtn.className = "loginBtn";
    }
}
loginBtn.click = function(){
  if(this.className!="loginBtn"){
    loginBtn.innerHTML = "登陆中";
    $.post("http://test.hfjava.com/shop/userlogin",$("form").serialize(),
        function(data){
          loginBtn.innerHTML = "登陆";
          if(data=="false"){
            pwderror.innerHTML = "您的用户或密码有误，请重新输入！";
          }else{
            location.href = "index.html?phone="+phone.value;
          }
        }
        );
  }
};